<?php
class BrandAction extends SystemCommonAction {
    public function showList() {
        
        $category_id = intval($_GET['category_id']);
        if($category_id>0){
            $condition = "category_id = '$category_id'";
        }
        $brand = D("BaseBrand");
        $brand_info = $brand->order('id desc')->where($condition)->select();
        $this->assign('brand_info',$brand_info);
        $this->display('index');
    }
    public function showAdd() {
        $id = intval($_GET['id']);
        if($id>0) {
             $brand = D("BaseBrand");
            $brand_info = $brand->where('id = '.$id)->find();
            if(count($brand_info)>0) {
                $this->assign('brand_info',$brand_info);
            }
        }
        $hangye = F('haneye');
        $this->assign('hangye',$hangye);
        $this->display('showAdd');
    }
    public function add() {
        $id = intval($_POST['id']);
        $arr = array();
        $arr['name'] = $_POST['name'];
//        $arr['category_id'] = $_POST['category_id'];
        $arr['industry_id'] = $_POST['industry_id'];
        $arr['py'] = $_POST['py'];
       
        $brand = D("BaseBrand");
        if($id>0) {
            $brand_info = $brand->where('id = '.$id)->find();
            if(count($brand_info)>0) {
                $rs = $brand -> where('id = '.$id) ->save($arr);
                if($rs) {
                    $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
                    $this->success('修改成功！');
                }else {
                    $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
                    $this->success('修改失败！');
                }
                return true;
            }
        }
        if($brand->add($arr)) {
            $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
            $this->success('成功！');
        }
        else {
            $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
            $this->success('失败！');
        }


    }

    public function del() {
        $id = intval($_GET['id']);
        if($id>0) {
             $brand = D("BaseBrand");
            $brand_info = $brand->where('id = '.$id)->find();
            if(count($brand_info)>0) {
                if($brand->where('id = '.$id)->delete()) {
                    $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
                    $this->success('成功！');
                }
            }
        }
        $this->assign('jumpUrl',__APP__.'/Admin/Brand/showList');
        $this->success('失败！');
    }
    

    
}
?>
